import 'package:chat_app_project/constants.dart';
import 'package:chat_app_project/screens/messages/components/body.dart';
import 'package:chat_app_project/tool/audio_player.dart';
import 'package:chat_app_project/util/toast_util.dart';
import 'package:flutter/material.dart';
import 'package:wukongimfluttersdk/entity/channel.dart';

//聊天页面
class MessagesScreen extends StatefulWidget {
  WKChannel currentChannel;

  MessagesScreen({super.key, required this.currentChannel});

  @override
  State<MessagesScreen> createState() => _MessagesScreenState();
}

class _MessagesScreenState extends State<MessagesScreen> {
  AppBar buildAppBar() {
    return AppBar(
      automaticallyImplyLeading: false,
      title: Row(
        children: [
          const BackButton(),
          CircleAvatar(
            backgroundImage: NetworkImage(widget.currentChannel.avatar),
          ),
          const SizedBox(width: kDefaultPadding * 0.75),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(widget.currentChannel.channelName,
                  style: const TextStyle(fontSize: 16)),
              // Text('Active 3m ago', style: TextStyle(fontSize: 12))
            ],
          )
        ],
      ),
      actions: [
        IconButton(
            onPressed: () {
              ToastUtil.toast("暂未开放");
              // var roomId = Random.secure().nextInt(1000000);
              // Navigator.of(context).push(MaterialPageRoute(
              //     builder: (context) =>
              //         CallPage(channelId: widget.currentChannel.channelID,channelType: widget.currentChannel.channelType,roomId:  roomId.toString(),callStatus :CallStatusEnum.calling)));
            },
            icon: const Icon(Icons.call)),
        IconButton(onPressed: () {
          ToastUtil.toast("暂未开放");
        }, icon: const Icon(Icons.videocam)),
        const SizedBox(
          width: kDefaultPadding / 2,
        )
      ],
    );
  }

  @override
  void initState() {
    super.initState();
    //消息提醒过滤
    AudioTool.addFilter(widget.currentChannel.channelID);
  }

  @override
  void dispose() {
    super.dispose();
    //消息提醒过滤移除
    AudioTool.removeFilter(widget.currentChannel.channelID,duration: const Duration(seconds: 2));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: buildAppBar(),
      body: Body(
        currentChannel: widget.currentChannel,
      ),
    );
  }
}
